<template>
  <div class="decoration-wrap">
    <svg :width="`${svgWH[0]}px`" :height="`${svgWH[1]}px`" :style="`transform:scale(${svgScale[0]},${svgScale[1]});`">
      <defs>
        <polygon :id="polygonId" points="15, 46.5, 21, 47.5, 21, 52.5, 15, 53.5" />
      </defs>

      <circle
        cx="50"
        cy="50"
        r="45"
        fill="transparent"
        :stroke="colors[1]"
        stroke-width="10"
        stroke-dasharray="80, 100, 30, 100"
      >
        <animateTransform
          attributeName="transform"
          type="rotate"
          values="0 50 50;360 50 50"
          :dur="`${dur}s`"
          repeatCount="indefinite"
        />
      </circle>

      <circle
        cx="50"
        cy="50"
        r="45"
        fill="transparent"
        :stroke="colors[0]"
        stroke-width="6"
        stroke-dasharray="50, 66, 100, 66"
      >
        <animateTransform
          attributeName="transform"
          type="rotate"
          values="0 50 50;-360 50 50"
          :dur="`${dur}s`"
          repeatCount="indefinite"
        />
      </circle>

      <circle
        cx="50"
        cy="50"
        r="38"
        fill="transparent"
        :stroke="fade(colors[1] || defaultColor[1], 30)"
        stroke-width="1"
        stroke-dasharray="5, 1"
      />

      <use
        v-for="(foo, i) in new Array(20).fill(0)"
        :key="i"
        :xlink:href="`#${polygonId}`"
        :stroke="colors[1]"
        :fill="Math.random() > 0.4 ? 'transparent' : colors[0]"
      >
        <animateTransform
          attributeName="transform"
          type="rotate"
          values="0 50 50;360 50 50"
          :dur="`${dur}s`"
          :begin="`${i * dur / 20}s`"
          repeatCount="indefinite"
        />
      </use>

      <circle
        cx="50"
        cy="50"
        r="26"
        fill="transparent"
        :stroke="fade(colors[1] || defaultColor[1], 30)"
        stroke-width="1"
        stroke-dasharray="5, 1"
      />
    </svg>
  </div>
</template>

<script>
import { uuid } from '../../border/util'

import { fade } from '../../border/util/fade.js'
export default {
  name: 'HzxDecoration',
  props: {
    colors: {
      type: Array,
      default: () => (['rgba(3, 166, 224, 0.8)', 'rgba(3, 166, 224, 0.5)'])
    },
    width: {
      type: Number,
      default: 100
    },
    height: {
      type: Number,
      default: 100
    },
    dur: {
      type: Number,
      default: 3
    }
  },
  data() {
    const id = uuid()
    return {
      ref: 'decoration-9',

      polygonId: `decoration-9-polygon-${id}`,

      svgWH: [100, 100],

      svgScale: [1, 1]

    }
  },
  mounted() {
    this.calcScale()
  },
  methods: {
    calcScale() {
      this.svgScale = [this.width / this.svgWH[0], this.height / this.svgWH[1]]
    },
    fade
  }
}
</script>
<style lang="less" scoped="scoped">
.decoration-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;

}
</style>
